package cn.ruituo.adv2;

import java.util.*;

public class JiHe3 {
    public static void main(String[] args) {
        //set ，HashSet,TreeSet
        //不保证顺序，不允许重复
        Set<String> set=new HashSet<>();
        set.add("卢生");
        set.add("尾生");
        set.add("李大伟");
        set.add("卢生");
        set.add("java");
        System.out.println(set.size());
        System.out.println(set);
        System.out.println("-----------循环----------------------");
        for(String s:set){
            System.out.println(s);
        }
        //
        System.out.println("---------------迭代器--------------------");
        Iterator<String> ir = set.iterator();
        while(ir.hasNext()){
            String s=ir.next();
            System.out.println(s);
        }
        System.out.println(">>>>>>>>>>>>>>>>>>>>>企鹅>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        Set<Pengiun> s2=new HashSet<>();
        //按照你的规则定义好hashCode和equals
        s2.add(new Pengiun("大花",3,"帝企鹅"));
        s2.add(new Pengiun("二花",2,"帝企鹅"));
        s2.add(new Pengiun("小花",1,"小黄企鹅"));
        s2.add(new Pengiun("小花",15,"小蓝企鹅"));
        System.out.printf("%d只企鹅\n",s2.size());
        for(Pengiun pp:s2)
            System.out.println(pp);

        s2.remove(new Pengiun("二花",0,null));
        System.out.println("删除后："+s2);
    }
}
